package personal.vap.route.tracker.server;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.util.Date;
import java.lang.reflect.Type;

public class JsonUtils {
  public static class MyJsonSerializer implements JsonSerializer<Date> {
    @Override
    public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext 
               context) {
      return src == null ? null : new JsonPrimitive(src.getTime());
    }
  }

  public static class MyJsonDeserializer implements JsonDeserializer<Date> {
    @Override
    public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
 
      return json == null ? null : new Date(json.getAsLong());
    }
  };

}
